import { request } from '@/http/axios';
import { IBase, IRecords } from '../app';

export interface IUser extends IBase {
  id?: number;
  username: string;
  password: string;
  nickname: string;
  avatar: string;
  roleId: number | string;
}

function records(data) {
  return request<IRecords<IUser>>({
    url: '/sys/user/records',
    method: 'POST',
    data
  });
}

function upgrade(data) {
  const url = data.id ? '/sys/user/update' : '/sys/user/insert';
  return request({
    url,
    method: 'POST',
    data
  });
}

function del(id) {
  return request({
    url: '/sys/user/del',
    method: 'GET',
    params: {
      id
    }
  });
}
function logout() {
  return request({
    url: '/sys/user/logout'
  });
}
export const userModel = {
  records,
  upgrade,
  del,
  logout
};
